home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickTime / QuickTime 3 Interfaces & Libs / QTDevWin / CIncludes / UnicodeUtilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-21  |  11.7 KB  |  310 lines  |  [TEXT/dosa]

  1. /*
  2.      File:        UnicodeUtilities.h
  3.  
  4.      Contains:    Types, constants, prototypes for Unicode Utilities (Unicode input and text utils)
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    QuickTime 3.0
  8.  
  9.      Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __UNICODEUTILITIES__
  19. #define __UNICODEUTILITIES__
  20.  
  21. #ifndef __MACTYPES__
  22. #include <MacTypes.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. /*
  48.    -------------------------------------------------------------------------------------------------
  49.    CONSTANTS & DATA STRUCTURES
  50.    -------------------------------------------------------------------------------------------------
  51. */
  52. /*
  53.    -------------------------------------------------------------------------------------------------
  54.    UCKeyOutput & related stuff
  55.    The interpretation of UCKeyOutput depends on bits 15-14.
  56.    If they are 01, then bits 0-13 are an index in UCKeyStateRecordsIndex (resource-wide list).
  57.    If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  58.      or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  59.      then bits 0-15 are a single Unicode character.
  60.    Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  61.      output.
  62.    UCKeyCharSeq is similar, but does not support indices in UCKeyStateRecordsIndex. For bits 15-14:
  63.    If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  64.      or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  65.      then bits 0-15 are a single Unicode character.
  66.    Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  67.      output.
  68.    -------------------------------------------------------------------------------------------------
  69. */
  70.  
  71. typedef UInt16                             UCKeyOutput;
  72. typedef UInt16                             UCKeyCharSeq;
  73.  
  74. enum {
  75.     kUCKeyOutputStateIndexMask    = 0x4000,
  76.     kUCKeyOutputSequenceIndexMask = 0x8000,
  77.     kUCKeyOutputTestForIndexMask = 0xC000,                        /* test bits 14-15*/
  78.     kUCKeyOutputGetIndexMask    = 0x3FFF                        /* get bits 0-13*/
  79. };
  80.  
  81. /*
  82.    -------------------------------------------------------------------------------------------------
  83.    UCKeyStateRecord & related stuff
  84.    The UCKeyStateRecord information is used as follows. If the current state is zero,
  85.    output stateZeroCharData and set the state to stateZeroNextState. If the current state
  86.    is non-zero and there is an entry for it in stateEntryData, then output the corresponding
  87.    charData and set the state to nextState. Otherwise, output the state terminator from
  88.    UCKeyStateTerminators for the current state (or nothing if there is no UCKeyStateTerminators
  89.    table or it has no entry for the current state), then output stateZeroCharData and set the
  90.    state to stateZeroNextState.
  91.    -------------------------------------------------------------------------------------------------
  92. */
  93.  
  94.  
  95. struct UCKeyStateRecord {
  96.     UCKeyCharSeq                     stateZeroCharData;
  97.     UInt16                             stateZeroNextState;
  98.     UInt16                             stateEntryCount;
  99.     UInt16                             stateEntryFormat;
  100.                                                                 /* This is followed by an array of stateEntryCount elements*/
  101.                                                                 /* in the specified format. Here we just show a dummy array.*/
  102.     UInt32                             stateEntryData[1];
  103. };
  104. typedef struct UCKeyStateRecord            UCKeyStateRecord;
  105. /*
  106.    Here are the codes for entry formats currently defined.
  107.    Each entry maps from curState to charData and nextState.
  108. */
  109.  
  110. enum {
  111.     kUCKeyStateEntryTerminalFormat = 0x0001,
  112.     kUCKeyStateEntryRangeFormat    = 0x0002
  113. };
  114.  
  115. /*
  116.    For UCKeyStateEntryTerminal -
  117.    nextState is always 0, so we don't have a field for it
  118. */
  119.  
  120.  
  121. struct UCKeyStateEntryTerminal {
  122.     UInt16                             curState;
  123.     UCKeyCharSeq                     charData;
  124. };
  125. typedef struct UCKeyStateEntryTerminal    UCKeyStateEntryTerminal;
  126. /*
  127.    For UCKeyStateEntryRange -
  128.    If curState >= curStateStart and curState <= curStateStart+curStateRange,
  129.    then it matches the entry, and we transform charData and nextState as follows:
  130.    If charData < 0xFFFE, then charData += (curState-curStateStart)*deltaMultiplier
  131.    If nextState != 0, then nextState += (curState-curStateStart)*deltaMultiplier
  132. */
  133.  
  134. struct UCKeyStateEntryRange {
  135.     UInt16                             curStateStart;
  136.     UInt8                             curStateRange;
  137.     UInt8                             deltaMultiplier;
  138.     UCKeyCharSeq                     charData;
  139.     UInt16                             nextState;
  140. };
  141. typedef struct UCKeyStateEntryRange        UCKeyStateEntryRange;
  142. /*
  143.    -------------------------------------------------------------------------------------------------
  144.    UCKeyboardLayout & related stuff
  145.    The UCKeyboardLayout struct given here is only for the resource header. It specifies
  146.    offsets to the various subtables which each have their own structs, given below.
  147.    -------------------------------------------------------------------------------------------------
  148. */
  149.  
  150. struct UCKeyboardLayout {
  151.                                                                 /* header only; other tables accessed via offsets*/
  152.     UInt16                             keyLayoutHeaderFormat;        /* =kUCKeyLayoutHeaderFormat*/
  153.     UInt16                             keyLayoutDataVersion;        /* 0x0100 = 1.0, 0x0110 = 1.1, etc.*/
  154.     ByteOffset                         keyModifiersToTableNumOffset; /* required*/
  155.     ByteOffset                         keyToCharTableIndexOffset;    /* required*/
  156.     ByteOffset                         keyStateRecordsIndexOffset;    /* 0 => no table*/
  157.     ByteOffset                         keyStateTerminatorsOffset;    /* 0 => no table*/
  158.     ByteOffset                         keySequenceDataIndexOffset;    /* 0 => no table*/
  159. };
  160. typedef struct UCKeyboardLayout            UCKeyboardLayout;
  161.  
  162. struct UCKeyModifiersToTableNum {
  163.     UInt16                             keyModifiersToTableNumFormat; /* =kUCKeyModifiersToTableNumFormat*/
  164.     UInt16                             defaultTableNum;            /* For modifier combos not in tableNum[]*/
  165.     ItemCount                         modifiersCount;                /* Dimension for tableNum[]*/
  166.     UInt8                             tableNum[1];
  167.  
  168.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  169. };
  170. typedef struct UCKeyModifiersToTableNum    UCKeyModifiersToTableNum;
  171.  
  172. struct UCKeyToCharTableIndex {
  173.     UInt16                             keyToCharTableIndexFormat;    /* =kUCKeyToCharTableIndexFormat*/
  174.     UInt16                             keyToCharTableSize;            /* Max keyCode (128 for ADB keyboards)*/
  175.     ItemCount                         keyToCharTableCount;        /* Dimension for keyToCharTableOffsets[] (usually 6 to 12 tables)*/
  176.     ByteOffset                         keyToCharTableOffsets[1];
  177.  
  178.                                                                 /* Each offset in keyToCharTableOffsets is from the beginning of the resource to a*/
  179.                                                                 /* table as follows:*/
  180.                                                                 /*    UCKeyOutput        keyToCharData[keyToCharTableSize];*/
  181.                                                                 /* These tables follow the UCKeyToCharTableIndex.*/
  182.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  183. };
  184. typedef struct UCKeyToCharTableIndex    UCKeyToCharTableIndex;
  185.  
  186. struct UCKeyStateRecordsIndex {
  187.     UInt16                             keyStateRecordsIndexFormat;    /* =kUCKeyStateRecordsIndexFormat*/
  188.     UInt16                             keyStateRecordCount;        /* Dimension for keyStateRecordOffsets[]*/
  189.     ByteOffset                         keyStateRecordOffsets[1];
  190.  
  191.                                                                 /* Each offset in keyStateRecordOffsets is from the beginning of the resource to a*/
  192.                                                                 /* UCKeyStateRecord. These UCKeyStateRecords follow the UCKeyToCharTableIndex.*/
  193.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  194. };
  195. typedef struct UCKeyStateRecordsIndex    UCKeyStateRecordsIndex;
  196.  
  197. struct UCKeyStateTerminators {
  198.     UInt16                             keyStateTerminatorsFormat;    /* =kUCKeyStateTerminatorsFormat*/
  199.     UInt16                             keyStateTerminatorCount;    /* Dimension for keyStateTerminators[] (# of nonzero states)*/
  200.     UCKeyCharSeq                     keyStateTerminators[1];
  201.  
  202.                                                                 /* Note: keyStateTerminators[0] is terminator for state 1, etc.*/
  203.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  204. };
  205. typedef struct UCKeyStateTerminators    UCKeyStateTerminators;
  206.  
  207. struct UCKeySequenceDataIndex {
  208.     UInt16                             keySequenceDataIndexFormat;    /* =kUCKeySequenceDataIndexFormat*/
  209.     UInt16                             charSequenceCount;            /* Dimension of charSequenceOffsets[] is charSequenceCount+1*/
  210.     UInt16                             charSequenceOffsets[1];
  211.  
  212.                                                                 /* Each offset in charSequenceOffsets is in bytes, from the beginning of*/
  213.                                                                 /* UCKeySequenceDataIndex to a sequence of UniChars; the next offset indicates the*/
  214.                                                                 /* end of the sequence. The UniChar sequences follow the UCKeySequenceDataIndex.*/
  215.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  216. };
  217. typedef struct UCKeySequenceDataIndex    UCKeySequenceDataIndex;
  218. /* Current format codes for the various tables (bits 12-15 indicate which table)*/
  219.  
  220. enum {
  221.     kUCKeyLayoutHeaderFormat    = 0x1001,
  222.     kUCKeyModifiersToTableNumFormat = 0x2001,
  223.     kUCKeyToCharTableIndexFormat = 0x3001,
  224.     kUCKeyStateRecordsIndexFormat = 0x4001,
  225.     kUCKeyStateTerminatorsFormat = 0x5001,
  226.     kUCKeySequenceDataIndexFormat = 0x6001
  227. };
  228.  
  229. /*
  230.    -------------------------------------------------------------------------------------------------
  231.    Error codes - these will eventually move to Errors.[ahp]
  232.    The error code range for Unicode Utilities is -25340 to -25379.
  233.    -------------------------------------------------------------------------------------------------
  234. */
  235.  
  236.  
  237. enum {
  238.     kUCOutputBufferTooSmall        = -25340                        /* Output buffer too small for Unicode string result*/
  239. };
  240.  
  241. /*
  242.    -------------------------------------------------------------------------------------------------
  243.    Constants for keyAction parameter in UCKeyTranslate() 
  244.    -------------------------------------------------------------------------------------------------
  245. */
  246.  
  247.  
  248. enum {
  249.     kUCKeyActionDown            = 0,                            /* key is going down*/
  250.     kUCKeyActionUp                = 1,                            /* key is going up*/
  251.     kUCKeyActionAutoKey            = 2                                /* auto-key down*/
  252. };
  253.  
  254. /*
  255.    -------------------------------------------------------------------------------------------------
  256.    Bit assignments & masks for keyTranslateOptions parameter in UCKeyTranslate() 
  257.    -------------------------------------------------------------------------------------------------
  258. */
  259.  
  260.  
  261. enum {
  262.     kUCKeyTranslateNoDeadKeysBit = 0                            /* Prevents setting any new dead-key states*/
  263. };
  264.  
  265.  
  266. enum {
  267.     kUCKeyTranslateNoDeadKeysMask = 1L << kUCKeyTranslateNoDeadKeysBit
  268. };
  269.  
  270. /*
  271.    -------------------------------------------------------------------------------------------------
  272.    FUNCTION PROTOTYPES
  273.    -------------------------------------------------------------------------------------------------
  274. */
  275.  
  276. EXTERN_API( OSStatus )
  277. UCKeyTranslate                    (UCKeyboardLayout *        keyLayoutPtr,
  278.                                  UInt16                 virtualKeyCode,
  279.                                  UInt16                 keyAction,
  280.                                  UInt32                 modifierKeyState,
  281.                                  UInt32                 keyboardType,
  282.                                  OptionBits             keyTranslateOptions,
  283.                                  UInt32 *                deadKeyState,
  284.                                  UniCharCount             maxStringLength,
  285.                                  UniCharCount *            actualStringLength,
  286.                                  UniChar                 unicodeString[]);
  287.  
  288.  
  289.  
  290. #if PRAGMA_STRUCT_ALIGN
  291.     #pragma options align=reset
  292. #elif PRAGMA_STRUCT_PACKPUSH
  293.     #pragma pack(pop)
  294. #elif PRAGMA_STRUCT_PACK
  295.     #pragma pack()
  296. #endif
  297.  
  298. #ifdef PRAGMA_IMPORT_OFF
  299. #pragma import off
  300. #elif PRAGMA_IMPORT
  301. #pragma import reset
  302. #endif
  303.  
  304. #ifdef __cplusplus
  305. }
  306. #endif
  307.  
  308. #endif /* __UNICODEUTILITIES__ */
  309.  
  310.